#!/bin/sh
#行程表-周维度
table_name=app_trip_data_pyi

create_table_sql=$(cat <<EOF
    DROP TABLE IF EXISTS ${KUDU_DATABASE}.${table_name};
    CREATE TABLE IF NOT EXISTS ${KUDU_DATABASE}.${table_name}(
          tid                            bigint       COMMENT '通讯号',
          trip_mileage                   bigint          COMMENT '根据0200结果精准后的里程单位:M',
          trip_fuel                      bigint          COMMENT '根据0200结果精准后的油耗单位:ML',
          trip_duration                  bigint          COMMENT '行程时长单位:秒（行程结束时间-开始时间）=引擎工作时长engineWorkTime',
          cross_cities                   string       COMMENT '经过城市，逗号分隔',
          run_days                       int          COMMENT '经过城市，逗号分隔',
          update_time                    string       COMMENT '写入时间',
          PRIMARY KEY(tid)
    )PARTITION BY HASH(tid) PARTITIONS 30
    STORED AS KUDU
    TBLPROPERTIES (
        'kudu.master_addresses' = '${KUDU_MASTER}',
        'kudu.num_tablet_replicas'='1'
    );
EOF
)

impala-shell -i ${IMPALA_HOST} -d ${KUDU_DATABASE} -q "$create_table_sql"
if [ $? -ne 0 ] ; then
  echo "${table_name}表创建失败"
else
  echo "${table_name}表创建成功"
fi